package com.asia.algorithmcode.dynamicProgram;

import java.util.Arrays;

/**
 * @DESCRIPTION: 91 、 解码方法
 * @USER: wanfu
 * @DATE: 2025/4/23 星期三 14:32
 */
public class NumDecodings {

    public static void main(String[] args) {
        String str = "1123";
        System.out.println(new NumDecodings().numDecodings(str));
    }


    public int numDecodings(String s) {
        int n = s.length();
        s = " " + s;
        int[] counts = new int[n + 1];
        counts[0] = 1;
        char[] arr = s.toCharArray();

        for (int i = 1; i < n + 1; i++) {
            int a = arr[i] - '0';
            int b = (arr[i - 1] - '0') * 10 + (arr[i] - '0');

            if (a >= 1 && a <= 9) {
                counts[i] = counts[i - 1];
            }

            if (b >= 10 && b <= 26) {
                counts[i] += counts[i - 2];
            }
        }

        return counts[n];
    }


}
